package cn.zhz.springdoc.console.controller;

import cn.zhz.springdoc.console.mapper.IOpenApiMapper;
import cn.zhz.springdoc.console.po.OpenApiPo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.zhz.springdoc.console.constant.Constant.API_INFO_URL;

/**
 * @author ZHZ
 * @since 2022-11-15
 */

@RestController
@RequiredArgsConstructor
@RequestMapping
public class ApiDocsController {

    private final IOpenApiMapper iOpenApiMapper;

    @GetMapping(API_INFO_URL+"{groupName}")
    public String docs(@PathVariable String groupName) {
        OpenApiPo openApiPo = iOpenApiMapper.selectOne(Wrappers.lambdaQuery(OpenApiPo.class)
                .eq(OpenApiPo::getGroupName, groupName));
        return openApiPo.getOpenApiJson();
    }
}
